<?php 
	if(!empty($this->Item)):
		$shareButton = new Zendvn_View_Helper_CmsShareButton();
		$config = new Zendvn_Controller_Config(array('module'=>'admin',
												'fileConfig'=>'product-category.ini'));
		$itemConfig = $config->getconfig('item');
		$imgUrlThumb = FILE_URL . '/product/items/thumb1/';
		$imgUrl 	= FILE_URL . '/product/items/';
		$imgPathThumb = FILE_PATH . '/product/items/';
		
		$id			= $this->Item['id'];
		$name		= Zendvn_Filter_Filter::filterContent($this->Item['name'], 'filter');
		$cat_name	= Zendvn_Filter_Filter::filterContent($this->Item['cat_name'], 'filter');
		$content	= Zendvn_Filter_Filter::filterContent($this->Item['content']);
		$cat_name	= Zendvn_Filter_Filter::filterContent($this->Item['cat_name'], 'filter');
		$stockStatus = ($this->Item['instock'] > 0)?'Còn hàng':'Hết hàng';
		
		$price 		= $this->Item['price'];
   		$sell_off 	= $this->Item['sale_price'];
   		$newPrice 	= (empty($sell_off) || $sell_off == 0)?$price:$sell_off;
   		$textPrice 	= (empty($sell_off) || $sell_off == 0)?'Giá':'Giá khuyến mãi';
   		
   		$dataSheet	= $this->Item['data_sheet'];
   		if(!empty($dataSheet))
   			$arrData = json_decode($dataSheet, true);
		
		$picture 	= $this->Item['image'];
    	if(file_exists($itemConfig['uploadDir'] . '/' . $picture) && !empty($picture)){
			$picture = $itemConfig['uploadUrl'] . '/' . $picture;
		}else{
			$picture = FILE_URL . '/no-image.png';
		}
		
		$pictures = $this->Item['images'];
		if(!empty($pictures))
			$arrPicture = json_decode($this->Item['images'], true); 

			
		$linkPageShare = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		$options = array(
				'title' => $name,
				'description' => Zendvn_Filter_Filter::shortString(strip_tags($content))
				);	
		
		$xhtml = '';
		$arrSize = json_decode($this->Item['size'],true);
		$arrColor = json_decode($this->Item['color'],true);
		$arrStock = json_decode($this->Item['stock'],true);

 		$totalStock = 0;
 		$arrSizeStock = '';
 		if(!empty($arrStock)){
 			foreach ($arrStock as $ke => $va){
 				foreach ($arrStock[$ke] as $key => $val){
 					$totalStock += $val;
 				}
 			}
 		}

 		if(!empty($arrSize)){
			foreach($arrSize as $key=>$val){
				$size = $this->slbSize[$val];
				$xhtml.="<li stt='".$val."'>".$size."</li>";
			}
 		}
//		$first = current(json_decode($this->Item['stock'],true));
		
		$linkOrder = $this->cmsUrl(array(
									'module' => 'default',
									'controller' => 'index',
									'action' => 'order',
									'product_id' => $id
									));
?>

<div class="box-header">
                	<h3><?php echo $cat_name?></h3>
                </div>
            	<div class="box-left">
                    <div class="content">
                    	<div class="intro">
                        	<div class="picture">
                            	<div class="border_img">
                                	<a href="<?php echo $picture?>" onclick="return fancyBox(this);">
					              		<img src="<?php echo $picture?>" alt="beboshop" title="<?php echo $name?>">
					              	</a>
                                </div>
                                <div id="slide_img" class="more_pics">
                                	<ul>
                                    	<?php 
                                    		$newPic = array();
				                           	foreach ($arrPicture as $v):
				                               	if(file_exists($imgPathThumb . $v['name'])){
													$imgThumb = $imgUrlThumb . $v['name'];
													$imgOrginal = $imgUrlThumb . $v['name'];
												}else{
													$imgThumb = $imgOrginal = FILE_URL . '/no-image.png';
												}
												$newPic[$v['key']] = $v['name'];
				                    	?>
				                        	<li stt="<?php echo $v['key']; ?>">
				                        		<a href="<?php echo $imgOrginal?>" rel="group_thumb">
				                        			<img src="<?php echo $imgThumb?>" alt="maxx99" title="<?php echo $name?>" />
				                        		</a>
				                        	</li>
				                      	<?php endforeach;?>
                                    </ul>
                                </div>
                            </div>
                            <div class="information">
                            	<ul class="product-info">
                                	<li><span class="label">Tên sản phẩm</span>: <span class="red"><?php echo $name; ?></span></li>
                                	<?php if(!empty($sell_off) || $sell_off != 0):?>                              	
					             	<li><span class="label">Giá gốc</span>: <span class="strike"><?php echo number_format($price)?> VNĐ</span></li>
					             	<?php endif;?>                                	
					             	<li><span class="label"><?php echo $textPrice?></span>: <span class="red"><?php echo number_format($newPrice)?> VNĐ</span></li>                              	
<!--					             	<li><span class="label">Số lượng</span>: <span><?php echo $totalStock?></span></li>                              	-->
                                </ul>

								<?php if(!empty($xhtml)):?>
                                <div class="product-detail-group">
                                	<div class="name">Hãy chọn size</div>
                                	<ul id="stock">
                                		<?php echo $xhtml?>
                    				</ul>
                                </div>
                                <?php endif;?>
                                <?php if(!empty($newPic)):?>
                                <div class="product-detail-group">
                                	<div class="name">Hãy chọn màu</div>
                                	<ul id="imgclick" class="more_pics">
                                		<?php 
                                		$xhtml = '';
                                		if(!empty($newPic)){
											$newPic = array_unique($newPic);
											foreach($newPic as $key=>$val){
												$imgThumb = $imgUrlThumb . $val;
												$color	= Zendvn_Filter_Filter::filterContent($this->slbColor[$key], 'filter');
												$xhtml.='<li stt="'.$key.'"><span style="margin-bottom: 3px; display: inline-block;">'.strtoupper($color).'</span><a href="'.$imgOrginal.'" rel="group_thumb"><img src="'.$imgThumb.'" alt="maxx99" /></a></li>';
											}
										}
										echo $xhtml;
                                		?>
                    				</ul>
                                </div>
                                <?php endif;?>
                                <div class="button">
					              	<a href="<?php echo $linkOrder?>" onclick="return fancyBox(this)">Đặt hàng</a>
				            	</div>
                            </div>
                            <div class="clr"></div>
                            <?php if(!empty($sell_off) || $sell_off != 0):?>     
                            <span class="sale_icon"></span>
                            <?php endif;?>
                        </div>
                        <div class="detail">
                        	<p class="head_label">Chi tiết sản phẩm</p>
                            
                            <div class="share_button social_button"><?php echo $shareButton->socialButton($linkPageShare, $options);?></div>
	                		<div class="product_content">
	                			<?php echo $content?>
							</div>
                        </div>
                        <div class="clr"></div>
                    </div>
                </div>
                
                
                
 <?php endif;?>                
                
<script>
$(document).ready(function(){
	

	$("#imgclick li").click(function(){
		$("#slide_img li").hide();
		$("#slide_img li[stt='"+$(this).attr("stt")+"']").show();
	})
	$("#stock li").click(function(){
		$("#amount").html($(this).attr("stt"));
		$("#stock li").removeClass();
		$(this).addClass('active');
	})
	$('#slide_img').prettyGallery({
					'navigation': 'bottom',
					'itemsPerPage': 4,
					'next_label': '',
					'previous_label': ''
				});
	$('.more_pics li').click(function(){
		var srcThumb = $(this).find('img').attr('src');
		var srcOrginal = $(this).find('a').attr('href');
		
		$('.picture .border_img img').attr('src', srcThumb);
		$('.picture .border_img a').attr('href', srcOrginal);
		return false;
	})
});
</script>                
                
                
                
                